package com.justgame.project.cloud.common.constant;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Nacos Constant
 * @author ZhouWeiBo
 * @create 2022/4/25
 */
@SuppressWarnings("all")
public interface NacosConstant {
    /**
     * 仅限测试开发环境开放Nacos 8848端口
     * 线上环境一定要关闭8848外网端口开放
     */
    List<String> NACOS_DEV_ADDRS = Arrays.asList("43.138.45.93:8848");
    List<String> NACOS_PROD_ADDRS = Arrays.asList("43.138.45.93:8848");
    String NACOS_CONFIG_PREFIX = "DataTurbine";
    String NACOS_GROUP_SUFFIX = "-group";
    String NACOS_CONFIG_FORMAT = "yaml";
    String NACOS_CONFIG_JSON_FORMAT = "json";
    String NACOS_CONFIG_REFRESH = "true";
    String NACOS_CONFIG_GROUP = "DEFAULT_GROUP";

    public static String getNacosAddrs(String profile){
        switch (profile.toLowerCase()){
            case "dev":
                return NACOS_DEV_ADDRS.stream().collect(Collectors.joining(","));
            case "prod":
                return NACOS_PROD_ADDRS.stream().collect(Collectors.joining(","));
            default:
                return NACOS_DEV_ADDRS.stream().collect(Collectors.joining(","));
        }
    }

    static String dataId(String appName) {
        return appName + "." + "yaml";
    }

    static String dataId(String appName, String profile) {
        return dataId(appName, profile, "yaml");
    }

    static String dataId(String appName, String profile, String format) {
        return appName + "-" + profile + "." + format;
    }

    public static String sharedDataId() {
        return "data-turbine.yaml";
    }

    public static String sharedDataId(String profile) {
        return "data-turbine-" + profile + "." + "yaml";
    }

    static String sharedDataIds(String profile) {
        return "data-turbine.yaml,data-turbine-" + profile + "." + "yaml";
    }
}
